
*****PANEL A*****
est clear

use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(convexity_split)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

keep convexity_split monthyear 

winsor2 convexity_split, cuts(1 99) by(monthyear)

foreach i in 1 10 25 50 75 90 99{
egen p`i'=pctile(convexity_split_w), by(monthyear) p(`i')
}

egen mean_convex=mean(convexity_split_w), by(monthyear)

drop convexity_split convexity_split_w

duplicates drop
}

collapse p1 p10 p25 p50 p75 p90 p99 mean_convex
sum p1 p10 p25 p50 p75 p90 p99 mean_convex

*****PANEL B*****
use "$jfqa_rep/20_Stock_Setup.dta", clear

qui{
drop if missing(convexity_split)

drop if year<1963
drop if year==1963 & month<6

drop if year>2022
drop if year==2022 & month==12

rename ret_11_month mom_ret

drop if missing(bm_ratio) | missing(profit) | missing(asset) | missing(mom_ret) 
drop if missing(max_ret) | missing(iv_ff3) | missing(skew) | missing(illiquid) | missing(ret)

keep convexity_split mktcap bm_ratio profit asset mom_ret max_ret iv_ff3 skew illiquid ret monthyear 

*winsorize variables
winsor2 convexity_split, cuts(1 99) by(monthyear)
winsor2 mktcap, cuts(1 99) by(monthyear)
winsor2 bm_ratio, cuts(1 99) by(monthyear)
winsor2 profit, cuts(1 99) by(monthyear)
winsor2 asset, cuts(1 99) by(monthyear)
winsor2 mom_ret, cuts(1 99) by(monthyear)
winsor2 max_ret, cuts(1 99) by(monthyear)
winsor2 iv_ff3, cuts(1 99) by(monthyear)
winsor2 skew, cuts(1 99) by(monthyear)
winsor2 illiquid, cuts(1 99) by(monthyear)
winsor2 ret, cuts(1 99) by(monthyear)

gen log_bm=log(bm_ratio_w)
gen log_mktcap=log(mktcap_w)

rename convexity_split_w convex

foreach i in convex  {
foreach j in log_mktcap log_bm profit_w asset_w mom_ret_w ret_w illiquid_w iv_ff3_w skew_w max_ret_w {
bysort monthyear: egen `i'_`j'=corr(`i' `j')
}
}

foreach i in convex  {
foreach j in log_mktcap log_bm profit_w asset_w mom_ret_w ret_w illiquid_w iv_ff3_w skew_w max_ret_w {
drop if missing(`i'_`j')
}
}
}

foreach i in mktcap bm_ratio profit asset mom_ret ret iv_ff3 illiquid skew max_ret convex log_mktcap mktcap_w log_bm bm_ratio_w profit_w asset_w mom_ret_w ret_w iv_ff3_w illiquid_w skew_w max_ret_w  {
	drop `i'
}

duplicates drop

drop monthyear

collapse _all
